package com.albaba.designpattern.factory.text_003.factory;

import com.albaba.designpattern.factory.text_003.factory.impl.DiscountFreeGoodsFactory;
import com.albaba.designpattern.factory.text_003.factory.impl.SmallGiftFreeGoodsFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 工厂的工厂，用来创建工厂类对象
 * @Author zx
 * @Date 2025/2/19 14:59
 * @Version 1.0
 */
public class FreeGoodsFactoryMap {

    // 创建map集合 保存工厂对象
    private static final Map<Integer, FreeGoodsFactory> cachedFactoryMap = new HashMap<>();

    static {
        cachedFactoryMap.put(1, new DiscountFreeGoodsFactory());
        cachedFactoryMap.put(2, new SmallGiftFreeGoodsFactory());
    }

    public static FreeGoodsFactory getFactory(Integer type) {
        return cachedFactoryMap.get(type);
    }
}
